using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for RadioButtonListHelper
/// </summary>
public partial class ControlHelper
{
    public void FillDataTableToRadioButtonList(
    RadioButtonList radioButtonList,
    string displayMember,
    string valueMember,
    string selectedValue)
    {

         
        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        if (dataTable != null)
        {
            radioButtonList.DataSource = dataTable;
            radioButtonList.DataTextField = displayMember;
            radioButtonList.DataValueField = valueMember;
        }
        else
            radioButtonList.DataSource = null;
        radioButtonList.DataBind();
        if (selectedValue != "")
            radioButtonList.SelectedValue = selectedValue;
        
    }
    public void FillDataTableToRadioButtonList(
    RadioButtonList radioButtonList,
    string firstDisplayMember,
    string firstValueMember,
    string displayMember,
    string valueMember,
    string selectedValue)
    {
         
        DataTable dataTable =
        sqlServerProvider.GetDataTable( );

        if (dataTable != null)
        {
            if (firstDisplayMember != "")
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = firstDisplayMember;
                dataRow[1] = firstValueMember;
                dataTable.Rows.InsertAt(dataRow, 0);
            }
            radioButtonList.DataTextField = displayMember;
            radioButtonList.DataValueField = valueMember;
            radioButtonList.DataSource = dataTable;
            radioButtonList.DataBind();
            if (selectedValue != "")
                radioButtonList.SelectedValue = selectedValue;
        }
        else
        {
            radioButtonList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }

        
    }
    void FillStringToRadioButtonList(
    RadioButtonList radioButtonList,

    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            radioButtonList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        string[] valueCollection =
        sqlServerProvider.GetStrings();
        for (int i = 0; i < valueCollection.Length; i++)
        {
            radioButtonList.Items.Add(
            valueCollection[i]);
        }

    }
    public void FillArrayListToRadioButtonList(
    RadioButtonList radioButtonList,
    string firstDisplayMember,
    string firstValueMember,
    string selectedValue)
    {
         
        ArrayList arrayList =
        sqlServerProvider.GetArrayList( );
        if (arrayList.Count != 0)
        {
            FillArrayListToRadioButtonList(
            radioButtonList, arrayList,
            firstDisplayMember, firstValueMember);
            if (selectedValue != "")
                radioButtonList.SelectedValue = selectedValue;
        }

        
    }
    void FillArrayListToRadioButtonList(
    RadioButtonList radioButtonList,
    ArrayList arrayList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            radioButtonList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        for (int i = 0; i < arrayList.Count; i++)
        {
            string[] item = (string[])arrayList[i];
            radioButtonList.Items.Add(
            new ListItem(item[1], item[0]));
        }

    }
}
